---
description: Learn the different data storage options available for the Triplit client.
---

# Storage

Each client has the option for how they would like to store their data.

## Memory

If you would only like to store data ephemerally, you can use the memory storage engine. This will store your data in memory and will not persist across page refreshes.

If you use memory storage, data may be lost if the user refreshes the page before the data is sent to the server.

If no storage options are provided this is the default.

```typescript
import { TriplitClient } from '@triplit/client';

const client = new TriplitClient({
  storage: 'memory',
});
```

## IndexedDB

If you would like to persist data between refreshes in the browser you can use the IndexedDB storage engine. This will store your data in the browser's IndexedDB database.

```typescript
import { TriplitClient } from '@triplit/client';

const client = new TriplitClient({
  storage: 'indexeddb',
});

// Or provide your own name
const client = new TriplitClient({
  storage: {
    type: 'indexeddb',
    name: 'my-database',
  },
});
```

Note that passing `{ storage: 'indexeddb' }` to the constructor will create an IndexedDB databases with the default name `triplit`. If your application connects to multiple projects with separate clients, we recommend you create your own custom-named instances of `IndexedDBStorage` so that naming conflicts do not occur. You can inspect the IndexedDB database in the [browser's developer tools](https://developer.chrome.com/docs/devtools/storage/indexeddb).

### Caching

By default, the `TriplitClient` will cache all IndexedDB data in memory for fast access (10x faster than native IndexedDB, in some cases). If you want to disable this, you can set the `cache` option to `false` when creating the `TriplitClient`.

```typescript
const client = new TriplitClient({
  storage: {
    type: 'indexeddb',
    options: { useCache: false },
  },
});
```

## Sqlite

### In the browser

Triplit does not currently provide a Sqlite storage adapter for the browser. The Triplit server, which runs in node environments, can use the `sqlite` storage engine.

### In React Native

Triplit provides an `expo-sqlite` storage adapter for React Native applications. This adapter uses the [`expo-sqlite`](https://docs.expo.dev/versions/latest/sdk/sqlite/) package to store data on the device. Users of Expo 51 or greater can get started by importing the storage provider from `@triplit/db/storage/expo-sqlite`:

```ts
import { ExpoSQLiteKVStore } from '@triplit/db/storage/expo-sqlite';
import { TriplitClient } from '@triplit/client';

new TriplitClient({
  storage: new ExpoSQLiteKVStore('triplit.db'),
});
```

You may also instantiate the storage provider with an existing database instance:

```ts
import { ExpoSQLiteKVStore } from '@triplit/db/storage/expo-sqlite';
import * as SQLite from 'expo-sqlite';
import { TriplitClient } from '@triplit/client';

const cacheDB = SQLite.openDatabaseSync('triplit.db');

new TriplitClient({
  storage: new ExpoSQLiteKVStore(cacheDB),
});
```

## Clearing your database

To clear a `TriplitClient`'s database, you can call the `clear` method. The clear takes an optional parameter `full` which if set to `true` will clear the entire database including all schema and metadata. If `full` is set to `false` or not provided, only your application data will be cleared. Clearing this data will not sync, so it is useful if you need to purge the data on your client.

```typescript
const client = new TriplitClient({
  storage: 'indexeddb',
});

const full: boolean = ...;
async function clearCache() {
  await client.clear({ full });
}
```

If you are clearing your cache because a user is signing out, it is recommended to use this in conjuction with `client.endSession()` as explained in the [auth guide](/auth#modeling-sign-in-and-sign-out-flows).
